const fs = require('fs');
 
var fn_add = async (ctx, next) => {
  const file = ctx.request.body.files.file;    // 获取上传文件
  const reader = fs.createReadStream(file.path);    // 创建可读流
  const ext = file.name.split('.').pop();        // 获取上传文件扩展名
  const upStream = fs.createWriteStream(`static/${file.name}`);        // 创建可写流
  reader.pipe(upStream);    // 可读流通过管道写入可写流
  return ctx.body = {
    success: true,
    data: '上传成功'
  }
}

module.exports = {
  'POST /api/upload': fn_add
};